package cm.iccsoft.android.telecomcost.adapter;

import java.util.ArrayList;
import java.util.List;

import cm.iccsoft.android.telecomcost.entities.MonthlyThreshold;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class MonthlyThresholdSimpleAdapter extends ArrayAdapter<MonthlyThreshold> {

	private ArrayList<MonthlyThreshold> items;
	private Context _context;

	public MonthlyThresholdSimpleAdapter(Context context, int textViewResourceId,
			ArrayList<MonthlyThreshold> items) {
		super(context, textViewResourceId, items);
		this.items = items;
		_context = context;
	}

	/**
	 * @param context
	 * @param resource
	 * @param textViewResourceId
	 * @param objects
	 */
	public MonthlyThresholdSimpleAdapter(Context context, int resource,
			int textViewResourceId, ArrayList<MonthlyThreshold> objects) {
		super(context, resource, textViewResourceId, objects);
		this.items = objects;
		_context = context;
	}

	/**
	 * @param context
	 * @param resource
	 * @param textViewResourceId
	 */
	public MonthlyThresholdSimpleAdapter(Context context, int resource,
			int textViewResourceId) {
		super(context, resource, textViewResourceId);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param context
	 * @param textViewResourceId
	 * @param objects
	 */
	public MonthlyThresholdSimpleAdapter(Context context, int textViewResourceId,
			List<MonthlyThreshold> objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param context
	 * @param textViewResourceId
	 * @param objects
	 */
	public MonthlyThresholdSimpleAdapter(Context context, int textViewResourceId,
			MonthlyThreshold[] objects) {
		super(context, textViewResourceId, objects);
		// TODO Auto-generated constructor stub
	}

	/**
	 * @param context
	 * @param textViewResourceId
	 */
	public MonthlyThresholdSimpleAdapter(Context context, int textViewResourceId) {
		super(context, textViewResourceId);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		Log.i("MonthlyThresholdSimpleAdapter", "getting threshold_view");
		View v = convertView;
		if (v == null) {
			Log.i("MonthlyThresholdSimpleAdapter", "creating new threshold_view");
			LayoutInflater vi = (LayoutInflater) _context
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			v = vi.inflate(
					cm.iccsoft.android.telecomcost.R.layout.standard_view,
					null);
		} else {
			Log.i("Threshold_ListView", "using an existing threshold_view");
		}
		MonthlyThreshold threshold = items.get(position);
		if (threshold != null) {
			TextView txtTitle = (TextView) v
					.findViewById(cm.iccsoft.android.telecomcost.R.id.label);
			txtTitle.setText(threshold.getMonthNameLong() + " ( " + threshold.getAmount() + " )");			
		}
		return v;
	}
}
